﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}
@model IEnumerable<BabyToys.Models.DanhMuc>


<div style="background: #fff; text-align: right; height: 60px; width: 100%; font-size: 12px; border: 1px solid #ccc;">
    <span style="font-size: 18px; font-weight: bold; float: left; padding-top: 17px;padding-left: 15px;">
        <img src="../../Content/Images/Admin/product.png" />
        DANH MỤC SẢN PHẨM
    </span>
</div>


@using (Html.BeginForm())
{
   
}
<br />

    <a href="#" class="normal blue button input btnThemMoi">Thêm mới</a>
    <a href="~/admin" class="normal black button input">Thoát</a>
    <br />
    <br />
    <table cellspacing="0" rules="rows" class="rows" border="1" style="width: 100%; border-collapse: collapse;">
        <tr class="item_title" style="color: White; background-color: #CCCCCC; font-family: Tahoma; font-size: 12px; font-weight: bold; height: 30px;">
            <th>ID</th>
            <th>Tên danh mục</th>
            <th>Danh mục cha</th>
            <th>Hiển thị</th>
            <th></th>
        </tr>
        @RenderTable(Model, 1, "")
    </table>

@helper RenderTable(IEnumerable<BabyToys.Models.DanhMuc> DanhMucList, int id, string prefix)
{
    foreach (var dm in DanhMucList.Where(d => d.DanhMucCha.IdDanhMuc == id))
    {
        string prefix1 = prefix;
    <tr class="item_row" style="border-color: #F0F0F0; border-style: Solid; height: 40px;">
        
        <td class="item_float">
            <input type="hidden" value="@dm.IdDanhMuc" id="txtId"/>
            @dm.IdDanhMuc
        </td>
        <td class="item_float" style="text-align: left;">
            <input type="hidden" value="@dm.TenDanhMuc" id="txtTen"/>
            @prefix1@dm.TenDanhMuc
        </td>
        <td class="item_float">
            <input type="hidden" value="@dm.DanhMucCha.IdDanhMuc" id="txtDanhMucCha"/>
            @dm.DanhMucCha.TenDanhMuc
        </td>
        <td class="item_float">
             @{int idd = dm.IdDanhMuc;}
                            <input id="@Html.Raw("HienThi" + dm.IdDanhMuc)" type="checkbox" onclick="CapNhatHienThi(@idd)" @if (dm.HienThi == true)
                                                                                                  {
                                @:checked="checked"
                            }
                            />
                <script type="text/ecmascript">
                    function CapNhatHienThi(id) {
                        var ten = '#HienThi' + id;
                        var hienthi = $(ten).is(':checked') ? true : false;
                        //alert("a:"+x+"b:"+id);
                        var x = confirm("Bạn có chắc muốn ẩn danh mục này?")
                        if(x==true)
                        {
                            $.post("/AdminDanhMuc/CapNhatHienThi/", { "id": id, "hienthi": hienthi },
                                   function (data) {
                                       alert("Cập Nhật Thành Công");
                                       window.location.reload();
                                   });
                        }
                        else
                        {
                            window.location.reload();
                        }
                    }
                </script>
        </td>
        <td class="td-actions">
            <div class="hidden-phone visible-desktop action-buttons">
                <a href="~/AdminDanhMuc/SuaDanhMuc/@dm.IdDanhMuc" class="small blue button btnSua">Sửa</a>
            </div>
        </td>
    </tr>
    prefix1 += "________";
    @RenderTable(DanhMucList, dm.IdDanhMuc, prefix1)
    }
}
